package Telas;

import Gerenciar.GerenciarCidade;
import Gerenciar.GerenciarParceria;
import Gerenciar.GerenciarTelefoneParceria;
import Gerenciar.GerenciarTipoTelefone;
import Gerenciar.GerenciarEnderecoParceria;
import entidades.Cidade;
import entidades.Enderecoparceria;
import entidades.Parceria;
import entidades.Telefoneparceria;
import entidades.Tipotelefone;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 * @author Guilherme Roberty
 */
public class CadastroParcerias extends javax.swing.JInternalFrame {

    private Parceria parceria;
    private List<Telefoneparceria> ListaTelefones;
    private List<Cidade> listaCidades;
    private List<Tipotelefone> listaTipoTelefone;

    public CadastroParcerias() {
        initComponents();
        ListaTelefones=new ArrayList<>();
        preencherCmbCidade();
        preencherCmbTipoTelefone();
    }
    private static CadastroParcerias instance = null;

    public static CadastroParcerias getInstance() {
        if (instance == null) {
            instance = new CadastroParcerias();
        }
        return instance;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtParceria = new javax.swing.JTextField();
        txtCNPJ = new javax.swing.JTextField();
        txtDono = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtDataCadastro = new javax.swing.JFormattedTextField();
        jLabel5 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        btSalvarTelefone = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabTelefone = new javax.swing.JTable();
        btRemoverTelefone = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        txtQtdCupons = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtCEP = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtRua = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtNumero = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtBairro = new javax.swing.JTextField();
        cmbCidade = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtTelefone = new javax.swing.JFormattedTextField();
        jLabel16 = new javax.swing.JLabel();
        cmbTipoTelefone = new javax.swing.JComboBox();
        btSalvar = new javax.swing.JButton();

        setClosable(true);
        setTitle("Cadastro de Parcerias");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jLabel1.setText("Parceiro:");

        jLabel2.setText("CNPJ:");

        jLabel3.setText("Dono:");

        jLabel4.setText("Data de cadastro:");

        try {
            txtDataCadastro.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel5.setText("Email:");

        btSalvarTelefone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/db_add.png"))); // NOI18N
        btSalvarTelefone.setText("Salvar    ");
        btSalvarTelefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarTelefoneActionPerformed(evt);
            }
        });

        tabTelefone.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "id", "Numero", "Tipo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tabTelefone);
        tabTelefone.getColumnModel().getColumn(0).setMinWidth(0);
        tabTelefone.getColumnModel().getColumn(0).setMaxWidth(0);

        btRemoverTelefone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/db_remove.png"))); // NOI18N
        btRemoverTelefone.setText("Remover");
        btRemoverTelefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoverTelefoneActionPerformed(evt);
            }
        });

        jLabel6.setText("Quantidade de Cupons:");

        jLabel10.setText("CEP");

        jLabel11.setText("Rua:");

        jLabel12.setText("numero:");

        jLabel13.setText("Bairro:");

        jLabel14.setText("Cidade:");

        jLabel7.setText("Telefones:");

        jLabel8.setText("Endereço:");

        jLabel9.setText("Numero:");

        try {
            txtTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##) ####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel16.setText("Tipo:");

        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel10)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtCEP, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18)
                                            .addComponent(jLabel12)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18)
                                            .addComponent(jLabel14))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel6)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtQtdCupons, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel11)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtRua)))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel13)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtBairro))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(cmbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(0, 193, Short.MAX_VALUE))))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel3)
                                        .addComponent(jLabel1))
                                    .addGap(25, 25, 25)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtDono, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                                        .addComponent(txtParceria))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel5)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtEmail))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel2)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18)
                                            .addComponent(jLabel4)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtDataCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(btSalvarTelefone)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup()
                                                    .addComponent(jLabel9)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(txtTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(btRemoverTelefone))
                                            .addGap(18, 18, 18)
                                            .addComponent(jLabel16)
                                            .addGap(18, 18, 18)
                                            .addComponent(cmbTipoTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                            .addComponent(jLabel7))
                        .addGap(37, 37, 37))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addContainerGap(670, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btSalvar)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtParceria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtDono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(txtCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)
                        .addComponent(txtDataCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtQtdCupons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addComponent(jLabel8)
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtCEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(cmbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addGap(18, 34, Short.MAX_VALUE)
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(txtTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16)
                            .addComponent(cmbTipoTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btSalvarTelefone)
                        .addGap(18, 18, 18)
                        .addComponent(btRemoverTelefone))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btSalvar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        if(CamposValidos()){
            Parceria p = new Parceria();
            p.setCnpj(txtCNPJ.getText());
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
            try {
                p.setDatacadastro(dateFormat.parse(txtDataCadastro.getText()));
            } catch (ParseException ex) {
                Logger.getLogger(CadastroParcerias.class.getName()).log(Level.SEVERE, null, ex);
            }
            p.setDescricao(txtParceria.getText());
            p.setDono(txtDono.getText());
            p.setEmail(txtEmail.getText());
            p.setQtdcupons(Integer.parseInt(txtQtdCupons.getText()));
            Enderecoparceria e=new Enderecoparceria();
            e.setCep(Integer.parseInt(txtCEP.getText()));
            e.setNumero(Integer.parseInt(txtNumero.getText()));
            e.setRua(txtRua.getText());
            e.setBairro(txtBairro.getText());
            e.getCidade().setId(listaCidades.get(cmbCidade.getSelectedIndex()).getId());
            e.getCidade().setNome(cmbCidade.getSelectedItem().toString());
            
            Set s= new HashSet();
            s.add(e);
            System.out.println(s);
            //parceria.setEnderecoparcerias(s);
            Set telefones=new HashSet();
            for (int i = 0; i < ListaTelefones.size(); i++) {
                telefones.add(ListaTelefones.get(i));
            }
            p.setTelefoneparcerias(telefones);
            if (GerenciarParceria.gravar(p)) {
                JOptionPane.showMessageDialog(null, "Salvo com sucesso!");
                int idparceria = GerenciarParceria.ultimoId();
                p.setId(idparceria);
                e.setParceria(p);
                Boolean b=false;
                if(GerenciarEnderecoParceria.gravar(e)){
                    b=true;
                }else{
                    JOptionPane.showMessageDialog(null, "Erro ao gravar endereco!");
                }
                List<Telefoneparceria> lista=(List<Telefoneparceria>)ListaTelefones;
                for (int i = 0; i < lista.size(); i++) {
                    lista.get(i).setParceria(p);
                    if (GerenciarTelefoneParceria.gravar(lista.get(i))) {
                        b = true;
                    } else {
                        b = false;
                    }
                }
                if (b==false) {
                    JOptionPane.showMessageDialog(null, "Erro ao gravar telefone");
                }
            } else {
                JOptionPane.showMessageDialog(null, "Erro ao salvar!");
            }
        }
    }//GEN-LAST:event_btSalvarActionPerformed

    private void btSalvarTelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarTelefoneActionPerformed
        String s=txtTelefone.getText().trim().replaceAll("[()-]", "");
        if (s.trim().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Campo de telefone vazio! Insira um telefone valido!");
        } else {
            Telefoneparceria t = new Telefoneparceria();
            t.setNumero(txtTelefone.getText());
            t.getTipotelefone().setId(listaTipoTelefone.get(cmbTipoTelefone.getSelectedIndex()).getId());
            t.getTipotelefone().setDescricao(cmbTipoTelefone.getSelectedItem().toString());
            ListaTelefones.add(t);
            AtualizarTabelaTelefone();
            txtTelefone.setText("");
            cmbTipoTelefone.setSelectedIndex(0);
        }
    }//GEN-LAST:event_btSalvarTelefoneActionPerformed

    private void btRemoverTelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoverTelefoneActionPerformed
        if (tabTelefone.getSelectedRow() < 0) {
            JOptionPane.showMessageDialog(null, "Selecione uma linha na tabela.");
        } else {
            ListaTelefones.remove(tabTelefone.getSelectedRow());
            AtualizarTabelaTelefone();
        }
    }//GEN-LAST:event_btRemoverTelefoneActionPerformed

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        // TODO add your handling code here:
    }//GEN-LAST:event_formInternalFrameClosing

    
    private boolean CamposValidos() {
        if (txtParceria.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Campo parceria vazio!");
            return false;
        }
        if (txtDono.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Campo dono vazio!");
            return false;
        }
        if (txtEmail.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Email vazio!");
            return false;
        }
        if (txtQtdCupons.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Quantidade de cupons vazio!");
            return false;
        }
        if (txtDataCadastro.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Data de cadastro vazio!");
            return false;
        }
        if (txtCEP.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Campo CEP vazio!");
            return false;
        }
        if (txtBairro.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Campo bairro vazio!");
            return false;
        }
        if (txtCNPJ.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Campo CNPJ vazio!");
            return false;
        }
        if (txtNumero.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Campo numero vazio!");
            return false;
        }
        if (txtRua.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null,"Campo rua vazio!");
            return false;
        }
        if (tabTelefone.getRowCount()<0) {
            JOptionPane.showMessageDialog(null,"Nenhum telefone cadastrado! Insira um telefone.");
            return false;
        }
        return true;
    }
    
    private void preencherCmbCidade() {
        try {
            listaCidades = GerenciarCidade.trazerTodos();

        } catch (Exception ex) {
            Logger.getLogger(CadastroParcerias.class.getName()).log(Level.SEVERE, null, ex);
        }
        cmbCidade.removeAllItems();
        for (Cidade cidade : listaCidades) {
            cmbCidade.addItem(cidade.getNome() + "(" + cidade.getEstado().getDescricao() + ")");
        }
    }

    private void preencherCmbTipoTelefone() {
        try {
            listaTipoTelefone = GerenciarTipoTelefone.trazerTodos();

        } catch (Exception ex) {
            Logger.getLogger(CadastroParcerias.class.getName()).log(Level.SEVERE, null, ex);
        }
        cmbTipoTelefone.removeAllItems();
        for (Tipotelefone tipotelefone : listaTipoTelefone) {
            cmbTipoTelefone.addItem(tipotelefone.getDescricao());
        }
    }

    private void AtualizarTabelaTelefone() {
        limparTabelaTelefone();
        for (Telefoneparceria telefone : ListaTelefones) {
            Object[] os = new Object[3];
            os[0] = telefone.getId();
            os[1] = telefone.getNumero();
            os[2] = telefone.getTipotelefone().getDescricao();
            ((DefaultTableModel) tabTelefone.getModel()).addRow(os);
        }
    }

    private void limparTabelaTelefone() {
        int numLinhas = ((DefaultTableModel) tabTelefone.getModel()).getRowCount();
        for (int i = numLinhas - 1; i >= 0; i--) {
            ((DefaultTableModel) tabTelefone.getModel()).removeRow(i);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btRemoverTelefone;
    private javax.swing.JButton btSalvar;
    private javax.swing.JButton btSalvarTelefone;
    private javax.swing.JComboBox cmbCidade;
    private javax.swing.JComboBox cmbTipoTelefone;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabTelefone;
    private javax.swing.JTextField txtBairro;
    private javax.swing.JTextField txtCEP;
    private javax.swing.JTextField txtCNPJ;
    private javax.swing.JFormattedTextField txtDataCadastro;
    private javax.swing.JTextField txtDono;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtNumero;
    private javax.swing.JTextField txtParceria;
    private javax.swing.JTextField txtQtdCupons;
    private javax.swing.JTextField txtRua;
    private javax.swing.JFormattedTextField txtTelefone;
    // End of variables declaration//GEN-END:variables
}
